package com.ft.admix.bd.adapter;

import android.app.Activity;

import com.baidu.mobads.sdk.api.ExpressInterstitialAd;
import com.baidu.mobads.sdk.api.ExpressInterstitialListener;
import com.ft.admix.ad.MixCustomInterstitialAdapter;
import com.ft.admix.config.AdConfig;

public class InterstitialAdLoader extends MixCustomInterstitialAdapter {
    private ExpressInterstitialAd mInterstitialAd;

    @Override
    protected void loadNetworkAd(Activity context, AdConfig config) {
        mInterstitialAd = new ExpressInterstitialAd(context, config.getAdId());
        mInterstitialAd.setLoadListener(new ExpressInterstitialListener() {
            @Override
            public void onADLoaded() {
                callLoadSuccess();
            }

            @Override
            public void onAdClick() {
                callInterstitialAdClick();
            }

            @Override
            public void onAdClose() {
                callInterstitialAdClose();
            }

            @Override
            public void onAdFailed(int i, String s) {
                callLoadFailed(i, s);
            }

            @Override
            public void onNoAd(int i, String s) {
                callLoadFailed(i, s);
            }

            @Override
            public void onADExposed() {
                callInterstitialAdShow();
            }

            @Override
            public void onADExposureFailed() {

            }

            @Override
            public void onAdCacheSuccess() {

            }

            @Override
            public void onAdCacheFailed() {

            }

            @Override
            public void onLpClosed() {

            }
        });
    }

    @Override
    public void show(Activity activity) {
        if (this.mInterstitialAd != null) {
            mInterstitialAd.show(activity);
        }
    }

    @Override
    public void destroy() {
        super.destroy();
        if (mInterstitialAd != null) {
            mInterstitialAd.destroy();
        }
    }
}
